﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace sieuthi.Threelayer.DAL
{
    public class nhanvienDAL_control:Threelayer.VO.ketnoi
    {
        public List<VO.nhanvienVO> nhanvien_xem()
        {
            List<VO.nhanvienVO> list = new List<VO.nhanvienVO>();
            using (SqlCommand dbCmd = new SqlCommand("nhanvien_xem", GetConnection()))
            {
                VO.nhanvienVO obj = new VO.nhanvienVO();
                dbCmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.nhanvienIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return list;
        }
        public bool nhanvien_them(VO.nhanvienVO data)
        {
            try
            {
                using (SqlCommand dbCmd = new SqlCommand("nhanvien_them", GetConnection()))
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.Parameters.Add(new SqlParameter("@luong", data.Luong));
                    dbCmd.Parameters.Add(new SqlParameter("@magh", data.maGH));
                    dbCmd.Parameters.Add(new SqlParameter("@manv", data.MaNV));
                    dbCmd.Parameters.Add(new SqlParameter("@sdt", data.Sdt));
                    dbCmd.Parameters.Add(new SqlParameter("@ten", data.ten));
                    dbCmd.Parameters.Add(new SqlParameter("@ngaysinh", data.ngaysinh));
                    dbCmd.Parameters.Add(new SqlParameter("@quequan", data.quequan));
                    dbCmd.ExecuteNonQuery();
                }
            }
            catch
            {
                
            }

            return true;
        }
        public bool nhanvien_sua(VO.nhanvienVO data)
        {
            using (SqlCommand dbCmd = new SqlCommand("nhanvien_sua", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@luong", data.Luong));
                dbCmd.Parameters.Add(new SqlParameter("@magh", data.maGH));
                dbCmd.Parameters.Add(new SqlParameter("@manv", data.MaNV));
                dbCmd.Parameters.Add(new SqlParameter("@sdt", data.Sdt));
                dbCmd.Parameters.Add(new SqlParameter("@ten", data.ten));
                dbCmd.Parameters.Add(new SqlParameter("@ngaysinh", data.ngaysinh));
                dbCmd.Parameters.Add(new SqlParameter("@quequan", data.quequan));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
        public bool nhanvien_xoa(string manv)
        {
            using (SqlCommand dbCmd = new SqlCommand("nhanvien_xoa", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@manv", manv));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
    }
    }
